package wsh;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

class DBHelper{
	public Connection connection;
	public PreparedStatement preparedStatement;
	
	public DBHelper() throws SQLException, ClassNotFoundException{
		Class.forName("org.mariadb.jdbc.Driver");
		connection = DriverManager.getConnection("jdbc:mariadb://localhost:3306/gd","test","123");
	}
	
	public ResultSet DB(String sql) throws ClassNotFoundException, SQLException{
		preparedStatement = connection.prepareStatement(sql);
	    ResultSet resultSet = preparedStatement.executeQuery();
	    return resultSet;
	}
	
	public void excuteSql(String sql) throws SQLException{
		preparedStatement = connection.prepareStatement(sql);
	    preparedStatement.executeUpdate();
	}
	
	public void downConn() throws SQLException{
		connection.close();
	}
	
}